package com.android.readcard.utils.djlm.DJLMReader3.reader;

import android.graphics.Bitmap;

/**
 * Created by Sabirjan on 2017/10/13.
 * DJLMReader.
 * 飞宏电子
 */

public class BitmapTool {
    public static int convertByteToInt(byte paramByte) {
        int i = paramByte >> 4 & 0xF;
        int j = 0xF & paramByte;
        return i * 16 + j;
    }

    public static int[] convertByteToColor(byte[] paramArrayOfByte, int paramInt1, int paramInt2) {
        int i = paramArrayOfByte.length;
        if (i == 0) {
            return null;
        }
        int[] arrayOfInt = new int[i / 3];
        for (int n = 0; n < paramInt2; n++) {
            int i1 = n * paramInt1;
            for (int i2 = 0; i2 < paramInt1; i2++) {
                int i3 = (i1 + i2) * 3;
                int j = convertByteToInt(paramArrayOfByte[i3]);
                int k = convertByteToInt(paramArrayOfByte[(i3 + 1)]);
                int m = convertByteToInt(paramArrayOfByte[(i3 + 2)]);
                arrayOfInt[((paramInt2 - n - 1) * paramInt1 + i2)] = (j << 16 | k << 8 | m | 0xFF000000);
            }
        }
        return arrayOfInt;
    }

    public static Bitmap createRgbBitmap(byte[] paramArrayOfByte, int paramInt1, int paramInt2) {
        int[] arrayOfInt = convertByteToColor(paramArrayOfByte, paramInt1, paramInt2);
        if (arrayOfInt == null) {
            return null;
        }
        Bitmap localBitmap = Bitmap.createBitmap(arrayOfInt, 0, paramInt1, paramInt1, paramInt2, Bitmap.Config.ARGB_8888);
        return localBitmap;
    }
}
